package com.example.demo;

import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

import java.util.Map;

/**
 * Created by Rick on 2019/8/28.
 */
public class AccessImportSelector implements ImportSelector{
    @Override
    public String[] selectImports(AnnotationMetadata annotationMetadata) {
        Map<String, Object> annotationAttributes =  annotationMetadata.getAnnotationAttributes(EnableAccess.class.getName());
        Access.Type type = (Access.Type )annotationAttributes.get("type");
        String [] importClassName = new String[0];
        switch (type){
            case RPC:
                importClassName = new String[]{RpcAccess.class.getName()};
                break;
            case REST:
                importClassName = new String[]{RestAccess.class.getName()};
        }
        return importClassName;
    }
}
